﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using SVC.client;
namespace UI.Forms
{
    public partial class goodsclass : DevExpress.XtraEditors.XtraForm
    {
        public goodsclass()
        {
            InitializeComponent();
        }

        private void btn_new_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Forms.goodsclass_N frm = new goodsclass_N();
            frm.FatherRefresh = bindTreelist;
            frm.ShowDialog(this);
        }

        private void goodsclass_Load(object sender, EventArgs e)
        {
            bindTreelist();
        }

        private void bindTreelist()
        {
            treeList1.DataSource = my.bw.GoodsClass_Get("ClassID", my.ACID);
            treeList1.ExpandAll();
        }

        private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e)
        {
            
            if (treeList1.Nodes.Count==0)
            {
                btn_update.Enabled = btn_delete.Enabled = false;
            }
            else
            {
                btn_update.Enabled = btn_delete.Enabled = true;
            }
        }

        private void btn_update_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            GoodsClass GC = treeList1.GetDataRecordByNode(treeList1.FocusedNode) as GoodsClass;
            if (GC !=null)
            {
                goodsclass_U frm = new goodsclass_U(GC);
                frm.FatherRefresh = bindTreelist;
                frm.ShowDialog(this); 
            }

        }

        private void btn_delete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            GoodsClass GC = treeList1.GetDataRecordByNode(treeList1.FocusedNode) as GoodsClass;
            if (GC != null)
            {
                string result = my.bw.GoodsClassByClassID_Delete(GC.ClassID, my.ACID);
                if (string.IsNullOrWhiteSpace(result))
                {
                    bindTreelist();
                }
                else
                {
                    Comm.ShowErorr(result);
                }
            }
        }
    }
}